package service.impl;

import redis.clients.jedis.Jedis;
import service.RedisService;

public class RedisServiceImpl implements RedisService {
    private Jedis jedis = new Jedis("127.0.0.1",6379);
    @Override
    public boolean set(String key, String value) {
        try {
            jedis.set(key,value);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean setEx(String key, String value, int secondes) {
        try {
            jedis.setex(key,secondes,value);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public String get(String key) {
        return jedis.get(key);
    }

    @Override
    public Long ttl(String key) {
        try {
            return jedis.ttl(key);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
